﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;

namespace PocketMahjong.Core
{
	public class RandomArrange: IArrangeStrategy
	{
		private List<Tile> _initLayout = new List<Tile>();

		public void Arrange(Board board)
		{
			Random rnd = new Random();
			_initLayout.Clear();
			var tiles = new List<Tile>(TileSet.GetAllTiles());
			foreach (Position pos in board.AllPositions)
			{
				var i = rnd.Next(tiles.Count);
				board[pos] = tiles[i];
				_initLayout.Add(tiles[i]);
				tiles.RemoveAt(i);
			}
		}

		public void Restore(Board board)
		{
			if (_initLayout.Count == 0)
				Arrange(board);
			else
			{
				int i = 0;
				foreach (Position pos in board.AllPositions)
				{
					board[pos] = _initLayout[i];
					i++;
				}
			}
		}
	}
}
